package com.example.adminLite.exception;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@ControllerAdvice
public class WebRunExceptionHandel {


    @ExceptionHandler(value = WebRunException.class)
    public String webRunException(WebRunException e, HttpServletRequest request, RedirectAttributes redirectAttributes)
    {
        redirectAttributes.addAttribute("errorMessage", e.getMessage());
        redirectAttributes.addAttribute("id", 3);
        String requestURI = request.getHeader("Referer");
//        return e.getMessage() + requestURI;
        return "redirect:" + requestURI;
    }

}
